home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Text⁄Files
/
Voyeur 1.1.1
/
Voyeur ƒ
/
v code ƒ
/
v.c
< prev
next >
Wrap
Text File
|
1994-02-27
|
5KB
|
198 lines
/**********************************************************************\
File: v.c
Purpose: This module handles Voyeur initialization and shutdown,
opening a new file (dispatch routine), and handling clicks
and keypresses in the main window.
Voyeur -- a no-frills file viewer
Copyright ©1993-4, Mark Pilgrim
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program in a file named "GNU General Public License".
If not, write to the Free Software Foundation, 675 Mass Ave,
Cambridge, MA 02139, USA.
\**********************************************************************/
#include "v.h"
#include "v meat.h"
#include "program globals.h"
#include "v files.h"
#include "v file management.h"
#include "v find.h"
#include "v error.h"
#include "v window maintenance.h"
#include "msg menus.h"
#include "msg graphics.h"
#include "msg environment.h"
#include "util.h"
unsigned char hexchar[2][256];
unsigned char asciichar[256];
void InitProgram(void)
{
int i,j,k,count;
AppFile myFile;
gWhichFile=0;
for (i=0; i<16; i++)
{
for (j=0; j<16; j++)
{
hexchar[0][i*16+j]=(i<10) ? i+'0' : i+'A'-10;
hexchar[1][i*16+j]=(j<10) ? j+'0' : j+'A'-10;
}
}
StuffHex(&asciichar[0], "\p2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F");
StuffHex(&asciichar[64], "\p404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E2E");
StuffHex(&asciichar[128], "\p808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF");
StuffHex(&asciichar[192], "\pC0C1C2C3C4C5C6C7C8C92ECBCCCDCECFD0D1D2D3D4D5D6D7D8D92E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E2E");
CountAppFiles(&i, &j);
if ((j>0) && (i==0))
{
for (count=1; count<=j; count++)
{
gLastFile=gWhichFile;
gWhichFile=CountProgramWindows();
if (gWhichFile==MAX_WINDOWS)
{
HandleError(tooManyFilesErr);
for (k=count; k<=j; k++)
ClrAppFiles(k);
}
else
{
GetAppFiles(count, &myFile);
MyMakeFSSpec(myFile.vRefNum, 0, myFile.fName, &gTheFS[gWhichFile]);
HandleError(OpenTheEditWindow());
ClrAppFiles(count);
}
}
}
}
int NewEditWindow(void)
{
gLastFile=gWhichFile;
gWhichFile=CountProgramWindows();
if (gWhichFile==MAX_WINDOWS)
HandleError(tooManyFilesErr);
else
{
gTheFS[gWhichFile].name[0]=0x00;
if (GetSourceFile(&gTheFS[gWhichFile]))
return OpenTheEditWindow();
else return userCancelErr;
}
}
int OpenTheEditWindow(void)
{
int resultCode;
int i;
for (i=0; i<CountProgramWindows(); i++)
if ((i!=gWhichFile) && (gTheFS[gWhichFile].vRefNum==gTheFS[i].vRefNum) &&
(gTheFS[gWhichFile].parID==gTheFS[i].parID) &&
(Mymemcompare(gTheFS[gWhichFile].name, gTheFS[i].name, gTheFS[i].name[0]+1)))
{
SelectProgramWindow(GetProgramWindowFromIndex(i));
return allsWell;
}
gBufferOffset[gWhichFile]=0;
resultCode=OpenTheFile(&gTheFS[gWhichFile], &gTheRefNum[gWhichFile]);
if (resultCode!=allsWell)
return resultCode;
gOffscreenNeedsUpdate[kMainWindow]=TRUE;
OpenProgramWindow(gWhichFile);
return allsWell;
}
void ProgramUndo(void)
{
}
void ProgramEvent(void)
{
Point mouseLoc;
Rect theRect;
if (IsProgramWindow(FrontWindow()))
{
}
}
void ProgramKeyEvent(char charPressed)
{
int i;
if (IsProgramWindow(FrontWindow()))
{
ObscureCursor();
switch (charPressed)
{
case 0x1d: /* right arrow */
case 'N':
case 'n':
GoForward();
break;
case 0x1c: /* left arrow */
case 'P':
case 'p':
GoBack();
break;
case 'D':
case 'd':
DoDataFork();
break;
case 'R':
case 'r':
DoResourceFork();
break;
case 'B':
case 'b':
GoBeginning();
break;
case 'E':
case 'e':
GoEnd();
break;
case 'F':
DoFind(TRUE);
break;
case 'f':
DoFind(FALSE);
break;
case 'G':
case 'g':
if (gFindString[0]!=0x00)
DoFindAgain();
break;
}
}
}
void ShutDownProgram(void)
{
HandleFileMenu(closeAllItem);
}